﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace App1AppHandler
{
    public class FieldLootItems
    {
        public int MapX = -1;
        public int MapY = -1;

        public List<Loot> LootItems = new List<Loot>();

        public FieldLootItems() {}

        public string toXML(Character sendingToCharacter)
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("fieldlootitems");
            xmldoc.WriteAttributeString("MapX", MapX.ToString());
            xmldoc.WriteAttributeString("MapY", MapY.ToString());
            
            string innerXml = "";
            foreach (Loot loot in LootItems)
            {
                innerXml = innerXml + loot.toXML(sendingToCharacter);
            }
            xmldoc.WriteStartElement("LootItems");
            if (innerXml != "") xmldoc.WriteRaw(innerXml);
            xmldoc.WriteEndElement();

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
